/*
 * 
 */
package com.yuanmei.stockeyes.charts;

import cn.limc.androidcharts.event.IZoomable;
import cn.limc.androidcharts.view.GridChart;
import cn.limc.androidcharts.view.SlipLineChart;
import cn.limc.androidcharts.view.SlipStickChart;
import android.content.Context;
import android.graphics.Color;
import android.util.Log;

import com.yuanmei.stockeyes.artifacts.Extensions;

import java.lang.reflect.Constructor;
import java.util.ArrayList;

public class TalibChartFactory  {
    private static final String TAG = "TalibChartFactory";

//    public enum TaIndex{
//        VOL,
//        MACD,
//        DMA,
//        KDJ, // TODO: 2017/2/18
//        BIAS, // TODO: 2017/2/18
//        BRAR, // TODO: 2017/2/18
//        OBV,
//        EMV, // TODO: 2017/2/18
//        RSI,
//        WR, // TODO: 2017/2/18
//        CCI, //
//        ADOSC
//        ADX                 Average Directional Movement Index
//        AROON
//        NATR
    // TSF
    //    }

    public static String[] sTalibChartClasses = {
            TalibVolChart.class.getName(),
            TalibAmountChart.class.getName(),
            TalibMacdChart.class.getName(),
            TalibKdjChart.class.getName(),
            TalibDmaChart.class.getName(),
            TalibObvChart.class.getName(),
            TalibRsiChart.class.getName(),
            TalibCciChart.class.getName(),
            TalibAdoscChart.class.getName(),
            TalibAdxChart.class.getName(),
            TalibAroonChart.class.getName(),
            TalibNatrChart.class.getName(),
            TalibTsfChart.class.getName(),
    };

    public static void commonInitSlipStickChart(SlipStickChart slipchart) {
        slipchart.setZoomBaseLine(IZoomable.ZOOM_BASE_LINE_CENTER);
    }

    public static void commonInitSlipLineChart(SlipLineChart slipchart) {
        slipchart.setZoomBaseLine(IZoomable.ZOOM_BASE_LINE_CENTER);
    }

    public static void commonInitGridChart(GridChart chart) {
        chart.setAxisXColor(Color.TRANSPARENT);
        chart.setAxisYColor(Color.TRANSPARENT);
        chart.setLatitudeColor(Color.GRAY);
        chart.setLongitudeColor(Color.GRAY);
        chart.setBorderColor(Color.TRANSPARENT);
        chart.setLongitudeFontColor(Color.WHITE);
        chart.setLatitudeFontColor(Color.WHITE);

        chart.setLatitudeFontSize(Extensions.spToPixels(chart.getContext(), 10));

        chart.setDisplayCrossXOnTouch(false);
        chart.setDisplayCrossYOnTouch(false);

        chart.setLatitudeNum(4);
        chart.setLongitudeNum(3);
        chart.setDisplayLongitudeTitle(false);
        //chart.setDisplayLatitudeTitle(true);
        //chart.setDisplayLatitude(true);
        //chart.setDisplayLongitude(true);
        chart.setBackgroundColor(Color.BLACK);
        
        chart.setDataQuadrantPaddingTop(0);
        chart.setDataQuadrantPaddingBottom(0);
        chart.setDataQuadrantPaddingLeft(0);
        chart.setDataQuadrantPaddingRight(0);
        chart.setAxisYTitleQuadrantWidth(0);
        chart.setAxisXTitleQuadrantHeight(0);
        chart.setAxisXPosition(GridChart.AXIS_X_POSITION_BOTTOM);
        chart.setAxisYPosition(GridChart.AXIS_Y_POSITION_LEFT);
    }
    
//    public static ITalibChart createTalibChart(TaIndex index, Context context) {
//        ITalibChart retChart;
//
//        retChart = null;
//        switch (index) {
//            case MACD:
//                retChart = new TalibMacdChart(context);
//                break;
//            default:
//                break;
//        }
//        return retChart;
//    }

    public static ArrayList<ITalibChart> createWholeTalibCharts(Context context) {
        ArrayList<ITalibChart> wholeTalibCharts;

        wholeTalibCharts = new ArrayList<ITalibChart>();

        for (String chartClassName : sTalibChartClasses) {
            try {
                Class chartClass = Class.forName(chartClassName);
                Constructor chartConstructor = chartClass.getConstructor(Context.class);
                ITalibChart talibChart = (ITalibChart) chartConstructor.newInstance(context);
                wholeTalibCharts.add(talibChart);
            } catch (Exception e) {
                Log.e(TAG, "Create " + chartClassName + " meet excepion:" + e.getMessage());
                e.printStackTrace();
            }
        }
        return wholeTalibCharts;
    }
}
